package com.android.pluginasm

import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes

class PTestClassVisitor(classVisitor: ClassVisitor) : ClassVisitor(Opcodes.ASM7, classVisitor) {

    private var mClassName: String? = null

    private val tag = this.javaClass.simpleName

    override fun visit(
        version: Int,
        access: Int,
        name: String?,
        signature: String?,
        superName: String?,
        interfaces: Array<out String>?
    ) {
        super.visit(version, access, name, signature, superName, interfaces)
        mClassName = name
    }

    override fun visitMethod(
        access: Int,
        name: String?,
        descriptor: String?,
        signature: String?,
        exceptions: Array<out String>?
    ): MethodVisitor {
        val methodVisitor = super.visitMethod(access, name, descriptor, signature, exceptions)
        println("$tag method=${name}")
        println("$tag class=${mClassName}")
        if (mClassName == "com/android/testpluginasm/logic/TestASM" && name == "test") {
            return PCustomizeMethodVisitor(api, methodVisitor, mClassName, access, name, descriptor)
        }
        return methodVisitor
    }

}